//判断:当前元素是否是被筛选元素的子元素
$.fn.isChildOf = function(b){
	return (this.parents(b).length > 0);
};
//判断:当前元素是否是被筛选元素的子元素或者本身
$.fn.isChildAndSelfOf = function(b){
	return (this.closest(b).length > 0);
};

/*弹出层*/
$.fn.showBox = function( options ){ 
    var o = $.extend({ 
    		id:"showBox",
              titleClass:"",
			  html:"",
			  headHtml:"",
			  style:null
			}, options);
	
	var t = this;
	
	var a = {
			init:function(){
				if($("#"+o.id).length !== 0){
					$("#"+o.id).remove();
				}
				this._createBox();
				this.showBox =  $("#"+o.id);
				this.close =  this.showBox.find(".showBox-close");
				this._bindEvent();
			},
			
			_createBox:function(){
				var html="<div id='"+o.id+"' class='showBox'>\
							<div class='toolSetBg showBox-bg'></div>\
							<span class='showBox-close png'></span>\
							<div class='showBox-content'><span class='showBox-content-info'>"+o.headHtml+"</span><h1><span class='png "+o.titleClass+"'></span></h1><div class='showBox-content-box'>"+o.html+"</div></div>\
						 </div>";
				$("body").append(html);
				this.showBox =  $("#"+o.id);
				this.showBox.css(o.style);
				this.close =  this.showBox.find(".showBox-close");
				
				
			},
			
			_bindEvent:function(){
				var _t = this;
				this.close.click(function(){
					_t.showBox.remove();
				})
				
			}
			
	}
	
	a.init();
}



/*弹出层*/
$.fn.alert = function( options ){ 
    var o = $.extend({ 
    		"width":"30%",
    		"content":"",
    		"closeTime":3000
			}, options);
    
    var a = {
    		init:function(){
    			clearTimeout($.fn.alert.timer||0);
    			this.creatHtml();
    		},
    		
    		/*创建HTML*/
    		creatHtml:function(){
    			if($(".alertClass") !== 0){
    				$(".alertClass").remove();
    			}
    			var html = "<div class='alertClass'>"+o.content+"</div>";
    			$("body").append(html);
    			this.target = $(".alertClass");
    			this.setPost();
    			this.bindEvent();
    			
    		},
    		
    		/*定位*/
    		setPost:function(){
    			
    			this.target.css({
    				"background":"#000000",
    				"color":"#fff",
					 "width":o.width,
					 "position":"absolute",
					 "zIndex":"101",
					 "border-radius":"10px",
					 "padding":"20px",
					 "textAlign":"center"
				});
    			
    			var height = $(window).height();
    			var width = $(window).width();
    			var maskHeight = this.target.height();
    			var maskWidth = this.target.width();
    			
    			this.target.css({
      				 "left":(width-maskWidth)/2,
   					 "top":(height-maskHeight)/2
   					
   				});
    			
    			this.anim();
    			
    			
    		},
    		
    		/*事件绑定*/
    		bindEvent:function(){
    			var _t = this;
    			
    			/*如果层显示出来 就隐藏*/
    			this.target.live("click",function(){
    				_t.anmiClose();
    			})
    			
    			/*规定时间后消失*/
    			$.fn.alert.timer = setTimeout(function(){
    				_t.anmiClose();
    			},o.closeTime);
    		},
    		
    		anim:function(){
    			var _t = this;
    			this.target.css({
    				 "-webkit-transform":"scale(0,0)",
    				 "opacity":0
  				});
    			
    			this.target.animate({
    				"-webkit-transform":"scale(1.1,1.1)",
    				"opacity":0.8
    			},300,"ease-in-out");
    			
    			setTimeout(function(){
    				_t.target.animate({
        				"-webkit-transform":"scale(1.0,1.0)"
        			},100);
    			},300)
    		},
    		
    		anmiClose:function(){
    			var _t = this;
    			this.target.animate({
    				"-webkit-transform":"scale(0,0)",
    				"opacity":0
    			},300,"ease-in-out");
    			
    			setTimeout(function(){
    				_t.target.remove();
    			},300)
    		}
    }
    
    a.init();
}



/*弹出层
 * 带确认和取消*/
$.fn.confirm = function( options ){ 
    var o = $.extend({ 
    		"width":"30%",
    		"content":"",
    		"hasYesButton":true,
    		"hasNoButton":true,
    		"yesButton":"确认",
    		"noButton":"取消",
    		"yesFun":function(){},
    		"noFun":function(){a.anmiClose();}
			}, options);
    
    var a = {
    		init:function(){
    			this.creatHtml();
    		},
    		
    		/*创建HTML*/
    		creatHtml:function(){
    			var html = "<div class='confirmClass'><div class='confirmContent'>"+o.content+"</div><div style='text-align:center'>" ;
    					
    			if(o.hasYesButton){
    				html += "<input name='' type='button' value='"+o.yesButton+"'  class='pokeyButton button-blue' id='confirm-yes'/>";
				}
    			
    			if(o.hasNoButton){
    				html += "<input name='' type='button' value='"+o.noButton+"'  class='pokeyButton button-blue' id='confirm-no'/>";
				}
    			html+="</div></div>";
    			
    			$("body").append(html);
    			this.target = $(".confirmClass");
    			this.content = $(".confirmContent");
    			this.yesButton = $("#confirm-yes");
    			this.noButton = $("#confirm-no");
    			this.setPost();
    			this.bindEvent();
    			
    		},
    		
    		/*定位*/
    		setPost:function(){
    			
    			this.target.css({
    				"background":"#000000",
    				 "width":o.width,
					 "position":"absolute",
					 "zIndex":"101",
					 "border-radius":"15px",
					 "padding":"10px"
					 
				});
    			
    			this.content.css({
    				"color":"#fff",
					"padding":"10px",
					"marginBottom":"20px",
					"textAlign":"center"
				});
    			
    			var height = $(window).height();
    			var width = $(window).width();
    			var maskHeight = this.target.height();
    			var maskWidth = this.target.width();
    			
    			this.target.css({
      				 "left":(width-maskWidth)/2,
   					 "top":(height-maskHeight)/2
   				});
    			
    			this.anim();
    		},
    		
    		/*事件绑定*/
    		bindEvent:function(){
    			var _t = this;
    			
    			this.yesButton.click(function(){
    				o.yesFun();
    			});
    			
    			this.noButton.live("click",function(){
    				o.noFun();
    			});
    		},
    		
    		anmiClose:function(){
    				var _t = this;
        			this.target.animate({
        				"-webkit-transform":"scale(0,0)",
        				"opacity":0
        			},300,"ease-in-out");
        			
        			setTimeout(function(){
        				_t.target.remove();
        			},300)
        		
    		},
    		
    		anim:function(){
    			var _t = this;
    			this.target.css({
    				 "-webkit-transform":"scale(0,0)",
    				 "opacity":0
  				});
    			
    			this.target.animate({
    				"-webkit-transform":"scale(1.1,1.1)",
    				"opacity":1
    			},300,"ease-in-out");
    			
    			setTimeout(function(){
    				_t.target.animate({
        				"-webkit-transform":"scale(1.0,1.0)"
        			},100);
    			},300)
    		}
    }
    
    a.init();
}



/*系统级--弹出层
 * 带确认和取消*/
$.fn.broadcast = function( options ){ 
    var o = $.extend({ 
    		"content":"",
    		"width":"66%",
    		"closeTime":3000	
			}, options);
    var _timer;
    
    var a = {
    		init:function(){
    			
    			this._createBox();
    			this._createTextBox();
    			
    		},
    		
    		_createBox:function(){
    			clearTimeout($.fn.broadcast._timer||0);
    			if($("#bulletinBox").length !== 0){
    				$("#bulletinBox").remove();
    			}
    			var html = "<div id='bulletinBox'></div>";
    			$("body").append(html);
    			this.box = $("#bulletinBox");
    			this.box.css({
    				"width":o.width,
    				"height":"40px",
    				"position":"absolute",
    				"z-index":1000,
    				"top":"2px",
    				"left":"17%",
    				"background":"#000",
    				"opacity":0.8,
    				"line-height":"40px",
    				"overflow":"hidden"
    				
    			});
    			
    			
    		},
    		
    		_createTextBox:function(){
    			var text = "<span class='bulletinBoxText'>"+o.content+"</span>";
    			this.box.append(text);
    			this.textBox = $(".bulletinBoxText");
    			this.textBox.css({
    				"position":"absolute",
    				"top":"0px",
    				"left":"10px",
    				"color":"#fff",
    				"line-height":"40px",
    				"white-space":"nowrap" 
    			});
    			
    			this.anmiScrollText();
    			
    		},
    		
    		anmiScrollText:function(){
    			//var left = this.textBox.css("left");
    			var pWidth = parseInt(this.box.width());
    			var width = parseInt(this.textBox.width());
    			var left = width - pWidth+10;
    			var _t = this;
    			
    			if(left<0){
    				$.fn.broadcast._timer = setTimeout(function(){
            			_t.closeBox();
            		},5000);
    				return;
    			}
    			
    			
    			
    			_t.textBox.animate({
        			"left":-left
        		},left*30);
        			
        			
    			$.fn.broadcast._timer = setTimeout(function(){
        			_t.closeBox();
        		},left*30+2000);
    				
    		},
    		
    		closeBox:function(){
    			$("#bulletinBox").remove();
    		}
    		
    }
    
    a.init();
}

;(function(){
	//共用基础类
	var G={
		getBaseURL:function(){
			var pathName = window.location.pathname,
				projectName = pathName.substring(0,pathName.substr(1).indexOf('/')+1);
			return "http://"+window.location.host + projectName;		
		},
		ajax:function(opt){
			var _opt=$.extend({dataType:"string",type:"get"},opt),
				url=_opt.url;
			var bu=G.getBaseURL();
			//默认给url加上当前工程的前辍
			if(url.substring(0,bu.length)!=bu){
				url=bu+url;
			}
			if(url.indexOf("?")>-1){
				url+="&"+(new Date()).getTime();
			}else{
				url+="?"+(new Date()).getTime();
			}
			
			return $.ajax({
				url:url,
				dataType:_opt.dataType,
				success:_opt.success,
				type:_opt.type,
				error:_opt.error
			})
		}
	}
	window.Game=G;
})();
(function() {
	/**
	 * 队列<br/> demo: var queue=new Queue();
	 */
	function Queue() {
		var me = this, queue = [], callback, // 回调函数
		dealFlag = !0;// 处理标记
		me.pop = function() {
			return queue.shift();
		}
		me.push = function(val) {
			queue.push(val);
		}
		/** 通知开始处理 */
		me.notify = function() {
			me.dealSyn(callback);
		}
		/**
		 * 同步处理<br/> dealFun:处理方法
		 */
		me.dealSyn = function(dealFun) {
			if (dealFlag == !0 && dealFun) {
				callback = dealFun;
				dealFlag = !1;
				deal(callback);
				dealFlag = !0;
			}
		}
		function toInt(val) {
			try {
				return parseInt(val);
			} catch (e) {
				return 3000;
			}
		}
		function deal(dealFun) {
			var item;
			while ((item = me.pop())) {
				try {
					dealFun(item);
				} catch (e) {
					console.log(e.name + ":" + e.message);
				}
			}
		}
	}
	window.Queue = Queue;
})();
/*
 * (function(){ function test(){ var queue=new Queue(); queue.push(1);
 * queue.push(2); queue.push(3); var i=6,j=1005; queue.dealSyn(function(v){
 * console.log(v); }) setInterval(function(){ if(i<j){ queue.push(i++);
 * queue.notify(); } },100) setInterval(function(){ if(j<3000){
 * queue.push(j++); queue.notify(); } },100) } test(); })();
 */

